package com.jojo.jojomall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jojo.common.utils.R;
import com.jojo.jojomall.product.dao.BrandDao;
import com.jojo.jojomall.product.dao.CategoryDao;
import com.jojo.jojomall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jojo.common.utils.PageUtils;
import com.jojo.common.utils.Query;

import com.jojo.jojomall.product.dao.CategoryBrandRelationDao;
import com.jojo.jojomall.product.entity.CategoryBrandRelationEntity;
import com.jojo.jojomall.product.service.CategoryBrandRelationService;

import java.util.ArrayList;
import java.util.List;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
@Autowired
private CategoryDao categoryDao;
@Autowired
private BrandDao brandDao;
    @Override
    public List<CategoryBrandRelationEntity> queryPage(Long params) {

        LambdaQueryWrapper<CategoryBrandRelationEntity> qw = new LambdaQueryWrapper<>();
        qw.eq(CategoryBrandRelationEntity::getBrandId,params);
        List<CategoryBrandRelationEntity> data = list(qw);


        return data;
    }

    @Override
    public void savedetail(CategoryBrandRelationEntity categoryBrandRelation) {
        String categoryName = categoryDao.selectById(categoryBrandRelation.getId()).getName();
        String brandName = brandDao.selectById(categoryBrandRelation.getBrandId()).getName();
        categoryBrandRelation.setBrandName(brandName);
        categoryBrandRelation.setCatelogName(categoryName);
        save(categoryBrandRelation);
    }
//在变更主表时候能够带着关系表做到改变
    @Override
    public void updateBrand(Long brandId, String name) {
        CategoryBrandRelationEntity ca = new CategoryBrandRelationEntity();
        LambdaUpdateWrapper<CategoryBrandRelationEntity> uw = new LambdaUpdateWrapper<>();
        uw.eq(CategoryBrandRelationEntity::getBrandId,brandId);
        ca.setBrandId(brandId);
        ca.setBrandName(name);
        update(ca,uw);
    }
    //在变更主表时候能够带着关系表做到改变
    @Override
    public void updateCategory(Long catId, String name) {
        CategoryBrandRelationEntity ca = new CategoryBrandRelationEntity();
        ca.setCatelogId(catId);
        ca.setCatelogName(name);
        LambdaUpdateWrapper<CategoryBrandRelationEntity> uw = new LambdaUpdateWrapper<>();
        uw.eq(CategoryBrandRelationEntity::getCatelogId,catId);
        this.update(ca,uw);
    }

}
